package com.team.controller;

import com.github.pagehelper.PageInfo;
import com.team.entity.PageParameter;
import com.team.entity.Registry;
import com.team.mapper.RegisInfoMapper;
import com.team.service.RegisInfoService;
import com.team.service.RegistryService;
import com.team.util.ParamForm;
import com.team.util.RegisInfo;
import com.team.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/registry")
public class RegistryController {
    @Autowired
    private RegistryService registryService;
    @Autowired
    private RegisInfoService regisInfoService;
    @RequestMapping("/add")
    @ResponseBody
    public Result add(@RequestBody Registry registry){
        int temp=registryService.addRegistry(registry);
        if (temp>0){
            return new Result("1000","success","添加成功");
        }else {
            return new Result("1001","error","添加失败");
        }
    }
    @RequestMapping("/showAll")
    @ResponseBody
    public Result<Map<String,Object>> showAll(@RequestBody ParamForm searchForm){
        //根据条件查询数据
        PageInfo<RegisInfo> pageInfo=registryService.getAllRegistryByParam(searchForm);
        Map<String,Object> map=new HashMap<>();
        map.put("total",pageInfo.getTotal());
        map.put("list",pageInfo.getList());
        if (pageInfo.getTotal()>0){
            return new Result<>("1000","success",map);
        }else {
            return new Result<>("1001","error",map);
        }
    }
    @RequestMapping("/end")
    @ResponseBody
    public Result end(Long registryId){
        registryService.updateStatus(registryId,3);
        return new Result("200","success");
    }
}
